<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item"
                  @keyup.enter.native="crud.toQuery"
        />
        <el-select v-model="query.type" clearable placeholder="类型 " class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
        </el-select>
        <rrOperation :crud="crud"/>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission"/>
      <el-upload class="upload-demo"
                   multiple  :on-exceed="handleExceed"
                 :before-upload="onBeforeUpload"
                  :show-file-list='false'
                 :http-request="Uploads"
      >
       <a href="http://gking-card.oss-cn-shenzhen.aliyuncs.com/IdCard/%E6%8C%87%E5%AF%BC%E4%BB%B7%E4%B8%8A%E4%BC%A0%E6%A8%A1%E6%9D%BF.xlsx">
         <el-button >  下载上传模版 </el-button>
       </a>

        <el-button size="small" type="primary">点击上传</el-button>
<!--        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>-->
      </el-upload>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
                 :title="crud.status.title" width="500px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="90px">
          <el-form-item label="行政区">
            <el-input v-model="form.district" style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="街道">
            <el-input v-model="form.street" style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="项目">
            <el-input v-model="form.project" style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="项目成交价">
            <el-input v-model="form.money" style="width: 370px;"/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading||loading" :data="crud.data" size="small" style="width: 100%;"
                @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55"/>
            <el-table-column v-if="columns.visible('id')" prop="id" label="id"/>
        <el-table-column v-if="columns.visible('district')" prop="district" label="行政区"/>
        <el-table-column v-if="columns.visible('street')" prop="street" label="街道"/>
        <el-table-column v-if="columns.visible('project')" prop="project" label="项目"/>
        <el-table-column v-if="columns.visible('money')" prop="money" label="项目成交价"/>
        <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','guidancePrice:edit','guidancePrice:del']" label="操作" width="150px"
                         align="center"
        >
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination/>
    </div>


 <el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="30%"
  :before-close="handleClose">
  <span>上传成功</span>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import crudGuidancePrice from '@/api/guidancePrice'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from '@/components/material'
import {upload} from '../../../utils/upload'


// crud交由presenter持有
const defaultCrud = CRUD({
  title: 'admin',
  url: '/api/guidancePrice',
  sort: 'id,desc',
  crudMethod: { ...crudGuidancePrice }
})
const defaultForm = { id: null, district: null, street: null, project: null, money: null, createTime: null }
export default {
  name: 'GuidancePrice',
  components: { pagination, crudOperation, rrOperation, udOperation, MaterialList },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      loading:false,
      dialogVisible:false,
    upExcel:'http://localhost:8009/api/guidancePrice/import',
      permission: {
        add: ['admin', 'guidancePrice:add'],
        edit: ['admin', 'guidancePrice:edit'],
        del: ['admin', 'guidancePrice:del']
      },
      rules: {},
      queryTypeOptions: [
        { key: 'district', display_name: '行政区' },
        { key: 'street', display_name: '街道' },
        { key: 'project', display_name: '项目' },
        { key: 'money', display_name: '项目成交价' }
      ]
    }
  },
  watch: {},
  methods: {
    Uploads(file){
      let that=this;
       that.loading=true;
      console.warn("进入上传")
      upload("/api/guidancePrice/import",file.file).then((res)=>{
        console.warn(res)
        that.dialogVisible=true;
       that.loading=false;
      })
    },
     handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {

          })
          .catch(_ => {});
      },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      } else {
        delete this.crud.params.district
        delete this.crud.params.street
        delete this.crud.params.project
        delete this.crud.params.money
      }
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    }
  }
}


</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>
